home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq15.zip / MEGAMAIL.SLT < prev    next >
Text File  |  1990-11-02  |  10KB  |  310 lines

  1. //-----------------------------------------------------------
  2. // MEGAMAIL.SL?   Telix script to fetch mail from a PCBoard BBS.
  3. //
  4. // This script is normally called from the script PCB.SLC.
  5. //
  6. // Please look at the comments through the whole file, and modify to
  7. // suit your needs, BEFORE you use it. Then recompile with CS MEGAMAIL.
  8. //-----------------------------------------------------------
  9. //
  10. // Author: Inge Vabekk
  11. //         Hamangskogen 108
  12. //         N-1300 SANDVIKA
  13. //         NORWAY
  14.  
  15. str myprot    [2]                        // My protocol
  16.    ,codename [10]                        // BBS codename.
  17.    ,help     [80]                        // Help line.
  18.    ,runstr   [80]                        // DSZ runstring (if used).
  19.                                          // Script and global names:
  20.    ,global     []="GLOBAL"               // Global script.
  21.    ,Cprot      []="CPROT"                // Current protocol.
  22.    ,prompt     []="PROMPT"               // Current command prompt.
  23.    ,mdir       []="MDIR"                 // Mail directory.
  24.    ,dsz        []="DSZ"                  // Code for DSZ (if in use).
  25.    ;     
  26.  
  27. int tol = 300                            // No activity for 30 sec.
  28.    ,tmark                                // makes script time out.
  29.    ,stat
  30.    ,PCBver                               // PCB version
  31.    ;
  32.  
  33. //-----------------------------------------------------------
  34. // MEGAmail script is entered here.                                   
  35. //-----------------------------------------------------------
  36.  
  37. main()
  38. {
  39. int c, i,                                // For tracking:
  40.     un,                                  // Upload Now
  41.     dn,                                  // Download Now
  42.     rt,                                  // Return.
  43.     pd,                                  // Back to ProDoor.
  44.     W;                                   // Still working...
  45.  
  46.   entry();                               // Updates status bar.
  47.   read (cprot,myprot) ;                  // Get current BBS protocol.
  48.  
  49.   un = track ("Upload Your",0);          // Wait for message.
  50.   pd = track ("Prodoor",1);              // Prodoor again.
  51.   W  = track ("se wait ...",0);          // Returning.
  52.   tmark = timer_start (tol);             // Give me a minute.
  53.  
  54.   while ((stat=trig()) > 0)              // answer any questions.
  55.   { if (stat == un)
  56.       break;                             // Upload Now?
  57.       goto done;                         // Door aborted.
  58.   }
  59.   
  60.   if (!carrier()) goto done;             // Fail?     
  61.  
  62.   i = 0;
  63.   do 
  64.   { c = cgetct(2);                       // Wait for a character.
  65.     printc(c);
  66.     if (isupper(c))                      // If "A" - "Z"
  67.     { setchr(codename,i,c);              // put it into name.
  68.       ++i;
  69.     }
  70.   } while (c != '.');
  71.  
  72.   setchr (codename,i,0);                 // Terminate with a zero.
  73.  
  74. // See if we can find the upload file.
  75. // ----------------------------------------------------------
  76.  
  77.   help = _up_dir;                        // Get upload directory.
  78.   strcat (help,codename);                // Copy codename to filename.
  79.   strcat (help,".UL");                   // Add extension.
  80.  
  81.   if (filesize(help) <= 0)               // No file to send?
  82.   { megabort();
  83.     goto done;
  84.   }
  85.  
  86. // Define new strings for tracking.
  87. //-----------------------------------------------------------
  88.  
  89.   un = track (" Now...",0);              // Upload Now.
  90.   dn = track ("gin Your",0);             // Download now.
  91.   rt = track ("system..",0);             // Return to system.
  92.   W  = track ("rking On",0);             // Still working....
  93.  
  94.   tmark = timer_start (tol);             // Give me a minute.
  95.  
  96.   while ((stat=trig()) > 0)              // answer any questions.
  97.   { if (stat == un)                      // Upload Now?
  98.     { track_free (un);                   // Release this track.
  99.       send_file();                       // Send it.
  100.     }
  101.     else if (stat == rt)                 // Return to system?
  102.       goto abort;
  103.  
  104.     else if (stat == dn)                 // Download now?
  105.       break;
  106.  
  107.     else if (stat == W)                  // Still working?
  108.       ;                                  // Just wait....
  109.   }
  110.   release();                             // Free all tracks and timer.
  111.   get_file();
  112.   if (carrier()) goto done;
  113.  
  114. abort:
  115.   release();
  116.   failtone();
  117.   return (-1);
  118.  
  119. done:
  120.   goodtone();
  121.   return (0);
  122. }
  123.  
  124. //-----------------------------------------------------------
  125. // Send upload mail file.
  126. //-----------------------------------------------------------
  127.  
  128. send_file()
  129. {
  130. int c;
  131.  
  132.   if (read (dsz,runstr) > 0)             // DSZ?
  133.   { strcat (runstr,help);                // Add filename to runstring.
  134.     while ((c=strchr(runstr,0,'\')) > 0)
  135.       setchr (runstr,c,'/');             // Replace '\' by '/'.
  136.     run (dsz,runstr,0);                  // Use DSZ.
  137.     flushbuf();                          // Flush input buffer.
  138.   }
  139.   else
  140.     send (subchr(myprot,0),help);        // Send file.
  141. }
  142.  
  143. //-----------------------------------------------------------
  144. // Get download mail file.
  145. //-----------------------------------------------------------
  146.  
  147. get_file()
  148. {
  149. int save;
  150.   save = _zmod_auto;                     // Save auto zmodem indicator.
  151.   _zmod_auto = 0;
  152.  
  153.   delay (5);
  154.   if (read (dsz,runstr) < 0)             // DSZ not defined:
  155.   { help = _down_dir;                    // Save download dir.
  156.     read (mdir,_down_dir);               // and change it.
  157.     receive (subchr(myprot,0),"");
  158.     _down_dir = help;                    // Restore download dir.
  159.   }
  160.   else
  161.   { newdir (_down_dir);                  // DSZ: Change directory.
  162.     strcat (runstr," r");                // Add parameters: Receive.
  163.     strlower (myprot);                   // Protocol.
  164.     strcat (runstr,myprot);
  165.     strcat (runstr," -y");               // OK to overwrite.
  166.     run (dsz,runstr,0);                  // Use DSZ.
  167.     newdir (_telix_dir);                 // Go back to TELIX directory!
  168.   }
  169.   flushbuf();                            // Flush input buffer.
  170.  
  171.   if (myprot=="Z")
  172.     waitfor ("**00",1);                 // Wait until this has passed, then
  173.   _zmod_auto = save;                     // restore auto zmodem indicator.
  174.   _down_dir = help;                      // Restore download dir.
  175.  
  176.   read (prompt,help);                    // Get command prompt.
  177.   waitfor (help,20);                     // Wait for next command.
  178. }
  179.  
  180. //----------------------------------------------------------
  181. // Abort Megamail door.
  182. //-----------------------------------------------------------
  183.  
  184. megabort()
  185. {
  186. int i, t1;
  187.  
  188.   for (i=0; i<3; ++i)                    // Three short beeps.
  189.   { tone (2400,6);
  190.     delay(1);
  191.   }
  192.  
  193.   mess ("No upload mail - Attempting to abort MegaMail door");
  194.  
  195.   t1 = track (" Command",0);             // Command
  196.   track (" wait ..",0);                  // Please wait...
  197.   track ("Prodoor",1);                   // Prodoor again.
  198.  
  199.   i=0;
  200.   tmark = timer_start (tol);             // Give me thirty seconds.
  201.   do  
  202.   { cputs ("^X");                        // Send Control-X.
  203.     delay (2);                           // as long as we're online.
  204.     if ((stat=track_hit(0)))             // If trigger,
  205.       timer_restart (tmark,tol);         // reset timer.
  206.     if (stat==t1)                        // If command, count to
  207.     { if (++i > 2) break;                // three to remove CNTL-X-es
  208.       cputs ("^M");                      // from his input buffer.
  209.     }
  210.   } while (!time_up(tmark) && carrier());
  211.  
  212.   return;                                // Return.
  213. }
  214.  
  215. //-----------------------------------------------------------
  216. // Routine to update colors and status bar.
  217. //-----------------------------------------------------------
  218.  
  219. entry ()
  220. {
  221.   _back_color = 1;
  222.   _fore_color = 14;
  223.   update_term();
  224. }
  225.  
  226. //-----------------------------------------------------------
  227. // Play fail tone.
  228. //-----------------------------------------------------------
  229.  
  230. failtone()
  231. {
  232.   int n;
  233.   for (n=140; n > 10; n = 100*n/120) 
  234.   { tone